
/**导入mutations的常量*/
import {
  Set_State,
  Destroy_State,
  Set_Token,
  Destroy_Token,

  Add_Goods_Count,
  Insert_Car_Goods,
  Destroy_Car_Goods,
} from './mutations-types'


//保证刷新页面数据不消失*
// function storeLocalStore (state) {
//   window.localStorage.setItem("publicTit",JSON.stringify(state));
// }


export default {

  /**保证state不被页面刷新清掉的函数*/
  // [RECEIVE_PUBLICHTIT] (state,{title}){
  //   state.publicTit = title
  //   storeLocalStore(state)
  // },

  /**
   * 为state赋值的方法
   * @param state
   * @param payload
   */
  [Set_State] (state, payload) {
  },

  /**
   * 删除state的方法
   * @param state
   * @param payload
   */
  [Destroy_State] (state, payload) {
    state.token = ''
    state.carList = []
  },

  /**
   * 为token赋值的方法
   * @param state
   * @param payload
   */
  [Set_Token] (state, payload) {
    // console.log('payload:'+payload);
    state.token = payload //存储到state中,但是刷新页面又会丢失,所以在同步到下面的localStorage中
  },

  /**
   * 清除token的方法
   * @param state
   * @param payload
   */
  [Destroy_Token] (state, payload) {
    state.token = ''
  },


  /**
   * 商品数量+
   * @param state
   * @param payload
   */
  [Add_Goods_Count] (state, payload) { //商品数量+
    payload.goods_count = payload.goods_count + payload.pre_count // 执行加操作
  },

  /**
   * 插入新的商品至购物车
   * @param state
   * @param payload
   */
  [Insert_Car_Goods] (state, payload) { //增加商品对象至数组
    payload.check = true //为商品加入一个是否选中的属性 check
    state.carList.push(payload)
  },

  /**
   * 删除购物车的商品
   * @param state
   * @param payload
   */
  [Destroy_Car_Goods] (state, payload) {
    state.carList.splice(payload, 1)
  }


}